package com.byf.cart.controller;

import com.byf.cart.domain.dto.AddCartDTO;
import com.byf.cart.service.CartService;
import com.byf.cart.vo.CartItemVo;
import com.byf.cart.vo.CartVo;
import com.byf.common.core.domain.Result;
import com.byf.common.core.web.controller.BaseController;
import com.byf.common.log.annotation.Log;
import com.byf.common.log.enums.BusinessType;
import com.byf.common.security.annotation.RequiresPermissions;
import com.byf.common.security.utils.SecurityUtils;
import com.byf.product.domain.PmsAttr;
import com.byf.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/cart")
public class CartController extends BaseController {
    @Autowired
    private CartService cartService;

    /**
     * 新增购物车
     * @param
     * @return
     */
    @PostMapping(value = "/addCart")
    public Result addCart(@RequestBody AddCartDTO addCartDto)
    {
        cartService.addCart(addCartDto);
        return success();
    }

    /**
     * 删除购物车详情信息
     * @param skuId
     * @return
     */
    @DeleteMapping("delCart/{skuId}")
    public Result delCart(@PathVariable Long skuId){
        cartService.delCart(skuId);
        return success();
    }

    /**
     * 获取购物车列表
     */
    @GetMapping("/getCartList")
    public Result getCartList()
    {
        startPage();
        List<CartVo> list = cartService.getCartList();
        return getDataTable(list);
    }

    /**
     * 修改购物车详情商品数量
     */
    @PutMapping("/updCartItemCount")
    public Result updCartItemCount(@RequestBody AddCartDTO addCartDTO)
    {
        cartService.updCartItemCount(addCartDTO);
        return success();
    }
}
